<template>
  <div class="home-product">
    <HomePanel title="居家" v-for="item in goods" :key="item.id">
      <div class="box">
        <RouterLink to="/" class="cover">
          <img :src="item.picture" alt="">
          <strong class="label">
            <span>{{ item.name }}馆</span>
            <span>{{ item.saleInfo }}</span>
          </strong>
        </RouterLink>
        <ul>
          <li v-for="good in item.goods" :key="good.id">
            <GoodItem :good="good" />
          </li>
        </ul>
      </div>
    </HomePanel>
  </div>
</template>

<script setup>
import HomePanel from './HomePanel.vue';
import GoodItem from './GoodItem.vue';
import { getGoodsAPI } from '@/apis/home'
import { onMounted, ref } from 'vue';

const goods = ref([])
const getGoodData = async () => {
  const res = await getGoodsAPI()
  goods.value = res.result
}

onMounted(() => getGoodData())
</script>

<style lang="scss" scoped>
.home-product {
  margin-top: 20px;
  background: #fff;

  .box {
    display: flex;

    .cover {
      width: 240px;
      height: 610px;
      margin-right: 10px;
      position: relative;

      img {
        width: 100%;
        height: 100%;
      }

      .label {
        width: 188px;
        height: 66px;
        color: #fff;
        font-size: 18px;
        position: absolute;
        top: 50%;
        left: 0;
        display: flex;
        line-height: 66px;

        span {
          text-align: center;

          &:first-child {
            width: 76px;
            background: rgba(0, 0, 0, 0.9);
          }

          &:last-child {
            flex: 1;
            background: rgba(0, 0, 0, 0.7);
          }
        }

      }
    }

    ul {
      width: 990px;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;

      li {
        width: 240px;
        height: 300px;
      }
    }
  }

}
</style>
